package com.tanhua.server.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 拦截器的配置
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Autowired
    private FreezeLoginInterceptor freezeLoginInterceptor;

    @Autowired
    private FreezeCommentInterceptor freezeCommentInterceptor;

    @Autowired
    private FreezeMovementInterceptor freezeMovementInterceptor;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")  // 指定拦截的资源；拦截所有资源
                .excludePathPatterns("/user/login", "/user/loginVerification");//指定放行的资源

        registry.addInterceptor(freezeLoginInterceptor)
                .addPathPatterns("/user/login");  // 指定拦截的资源；拦截登录

        registry.addInterceptor(freezeCommentInterceptor)
                .addPathPatterns("/comments");  // 拦截发布评论

        registry.addInterceptor(freezeMovementInterceptor)
                .addPathPatterns("/movements");  // 拦截发布动态
    }
}
